﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BUSINESS_OBJECT;

namespace CRM.customer
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        Invoicecls invce = new Invoicecls();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = invce.GetRecords(-99,"", "", -99, "",-99,Convert.ToDateTime( "1/1/1800"), false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            invce.ID = -99;
            invce.COMPANY_NAME = Txtname.Text;
            invce.COMPANY_ADDRESS = Txtcmpadd.Text;
            invce.PHONE_NO = Convert.ToInt64(Txtphone.Text);
            invce.EMAIL_ID = Txtemail.Text;
            invce.PAYMENT = Convert.ToInt64(Txtpymnt.Text);
            invce.DATE = Convert.ToDateTime(Txtdate.Text);
            invce.ISDELETED = false;
            invce.SaveRecords();
            Response.Redirect("invoice.aspx");
        }

        protected void btEdit_Command(object sender, CommandEventArgs e)
        {
            DataTable dt = invce.GetRecords(Convert.ToInt64(e.CommandArgument.ToString()), "", "", -99, "", -99, Convert.ToDateTime("1/1/1800"), false, " and ");
            Txtid.Text= dt.Rows[0]["ID"].ToString();
            Txtname.Text = dt.Rows[0]["COMPANY_NAME"].ToString();
            Txtcmpadd.Text = dt.Rows[0]["COMPANY_ADDRESS"].ToString();
            Txtphone.Text = dt.Rows[0]["PHONE_NO"].ToString();
            Txtemail.Text = dt.Rows[0]["EMAIL_ID"].ToString();
            Txtpymnt.Text =dt.Rows[0]["PAYMENT"].ToString();
            Txtdate.Text = dt.Rows[0]["DATE"].ToString();
        }
            
          

        protected void btDelete_Command(object sender, CommandEventArgs e)
        {
            DataTable dt =invce.GetRecords(Convert.ToInt64(e.CommandArgument.ToString()),  "", "", -99, "",-99, Convert.ToDateTime("1/1/1800"), false, " and ");
            invce.ID= Convert.ToInt64(dt.Rows[0]["ID"].ToString());
            invce.COMPANY_NAME = dt.Rows[0]["COMPANY_NAME"].ToString();
            invce.COMPANY_ADDRESS = dt.Rows[0]["COMPANY_ADDRESS"].ToString();
            invce.PHONE_NO=Convert.ToInt64(dt.Rows[0]["PHONE_NO"].ToString());
            invce.EMAIL_ID=dt.Rows[0]["EMAIL_ID"].ToString();
            invce.PAYMENT=Convert.ToInt64(dt.Rows[0]["PAYMENT"].ToString());
            invce.DATE=Convert.ToDateTime(dt.Rows[0]["DATE"].ToString());
            invce.ISDELETED=true;
            invce.SaveRecords();
            Response.Redirect("invoice.aspx");

        }

        

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void Btupdate_Click(object sender, EventArgs e)
        {
            invce.ID=Convert.ToInt64(Txtid.Text);
            invce.COMPANY_NAME = Txtname.Text;
            invce.COMPANY_ADDRESS=Txtcmpadd.Text;
            invce.PHONE_NO = Convert.ToInt64(Txtphone.Text);
            invce.EMAIL_ID = Txtemail.Text;
            invce.PAYMENT = Convert.ToInt64(Txtpymnt.Text);
            invce.DATE = Convert.ToDateTime(Txtdate.Text);
            invce.ISDELETED = false;
            invce.SaveRecords();
            Response.Redirect("invoice.aspx");


        }
    }
}
